home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / wcscmp.c < prev    next >
C/C++ Source or Header  |  1993-10-20  |  2KB  |  80 lines

  1. /* from Henry Spencer's stringlib */
  2. /* modified by ERS */
  3.  
  4. #include <stddef.h>
  5. #include <stdlib.h>
  6.  
  7. /*
  8.  * wcscmp - compare string s1 to s2
  9.  */
  10.  
  11. int                /* <0 for <, 0 for ==, >0 for > */
  12. wcscmp(scan1, scan2)
  13. register const wchar_t *scan1;
  14. register const wchar_t *scan2;
  15. {
  16.     register wchar_t c1, c2;
  17.  
  18.     if (scan1 == NULL)
  19.         return scan2 == NULL ? 0 : -1;
  20.     if (scan2 == NULL) return 1;
  21.  
  22.     do {
  23.         c1 = *scan1++; c2 = *scan2++;
  24.     } while (c1 && c1 == c2);
  25.  
  26.     /*
  27.      * The following case analysis is necessary so that characters
  28.      * which look negative collate low against normal characters but
  29.      * high against the end-of-string NUL.
  30.      */
  31.     if (c1 == c2)
  32.         return(0);
  33.     else if (!c1)
  34.         return(-1);
  35.     else if (!c2)
  36.         return(1);
  37.     else
  38.         return(c1 - c2);
  39. }
  40.  
  41. /*
  42.  * wcsncmp - compare at most n characters of string s1 to s2
  43.  */
  44.  
  45. int                /* <0 for <, 0 for ==, >0 for > */
  46. wcsncmp(scan1, scan2, n)
  47. register const wchar_t *scan1;
  48. register const wchar_t *scan2;
  49. size_t n;
  50. {
  51.     register wchar_t c1, c2;
  52.     register long count;
  53.  
  54.     if (scan1 == NULL) {
  55.         return scan2 == NULL ? 0 : -1;
  56.     }
  57.     if (scan2 == NULL) return 1;
  58.     count = n;
  59.     do {
  60.         c1 = *scan1++; c2 = *scan2++;
  61.     } while (--count >= 0 && c1 && c1 == c2);
  62.  
  63.     if (count < 0)
  64.         return(0);
  65.  
  66.     /*
  67.      * The following case analysis is necessary so that characters
  68.      * which look negative collate low against normal characters but
  69.      * high against the end-of-string NUL.
  70.      */
  71.     if (c1 == c2)
  72.         return(0);
  73.     else if (!c1)
  74.         return(-1);
  75.     else if (!c2)
  76.         return(1);
  77.     else
  78.         return(c1 - c2);
  79. }
  80.